#include "InetAddress.h"
#include <cstring>
#include <arpa/inet.h>

InetAddress::InetAddress()
{
}

InetAddress::InetAddress(sockaddr_in addr) : m_addr(addr)
{
}

InetAddress::InetAddress(const char *ip, uint16_t port)
{
    memset(&m_addr, 0, sizeof(m_addr));
    m_addr.sin_family = AF_INET;
    m_addr.sin_addr.s_addr = inet_addr(ip);
    m_addr.sin_port = ntohs(port);
}

const char *InetAddress::ip() const
{
    return inet_ntoa(m_addr.sin_addr);
}

uint16_t InetAddress::port() const
{
    return htons(m_addr.sin_port);
}

const sockaddr *InetAddress::addr() const
{
    return (sockaddr *)&m_addr;
}

void InetAddress::set_addr(const sockaddr_in &clientaddr)
{
    m_addr = clientaddr;
}

InetAddress::~InetAddress()
{
}